<template>
    <div>
        <Form :label-width="140" inline>
            <Form-item label="属地区划:">
                <area-linkage :areaCode.sync="queryParam.azdf0007"></area-linkage>
            </Form-item>
            <Form-item label="复核月度:">
                <Date-picker v-model="queryParam.cbxx0010" type="month" style="width: 150px"></Date-picker>
            </Form-item>
            <Form-item label="核对报告编号：">
                <Input v-model="queryParam.cbxx0008" placeholder=""
                       style="width: 160px"/>
            </Form-item>

            <Form-item label="复核数据状态：">
                <Select v-model="queryParam.cbxx0013" placeholder="" style="width: 160px">
                    <Option value="0">保障数据匹配成功</Option>
                    <Option value="1">保障数据匹配失败</Option>
                    <Option value="-2">属地区划匹配失败</Option>
                    <Option value="-1">核对报告获取失败</Option>
                </Select>
            </Form-item>
            <Form-item label="户主姓名：">
                <Input v-model="queryParam.cbxx0001" placeholder=""
                       style="width: 120px"/>
            </Form-item>
            <Form-item label="证件号码：">
                <Input v-model="queryParam.cbxx0002" placeholder=""
                       style="width: 150px"/>
            </Form-item>
            <Form-item label="当前救助状态：">
                <dictSelect dictCode="systemsubtype" :bindData.sync="queryParam.assistancetype"
                            style="width: 160px"/>
            </Form-item>
            <Form-item label="家庭编号：">
                <Input v-model="queryParam.azdf0001" placeholder=""
                       style="width: 160px"/>
            </Form-item>
            <Form-item label="低保证号：">
                <Input v-model="queryParam.ssca0014" placeholder=""
                       style="width: 150px"/>
            </Form-item>
            <Form-item label="性别：">
                <dictSelect dictCode="sex" :bindData.sync="queryParam.azcp0004"
                            style="width: 100px"/>
            </Form-item>
            <Form-item label="民族：">
                <dictSelect dictCode="nation" :bindData.sync="queryParam.azcp0007"
                            style="width: 100px"/>
            </Form-item>
            <Form-item label="健康状况：">
                <dictSelect dictCode="health" :bindData.sync="queryParam.azcp0009"
                            style="width: 130px"/>
            </Form-item>
            <Form-item label="残疾类别：">
                <dictSelect dictCode="disabilitytype" :bindData.sync="queryParam.azcp0504"
                            style="width: 100px"/>
            </Form-item>
            <Form-item label="残疾等级：">
                <dictSelect dictCode="disabilityclass" :bindData.sync="queryParam.azcp0505"
                            style="width: 100px"/>
            </Form-item>
            <Form-item label="劳动能力丧失情况：">
                <dictSelect dictCode="workability" :bindData.sync="queryParam.azcp0502"
                            style="width: 150px"/>
            </Form-item>
            <Row class="button_row">
                <span style="float: right;">
                     <Button type="primary" style="" @click="searchQuery2">查询</Button>
                <Button type="primary" style="margin-left: 8px" @click="searchReset">重置</Button>
                </span>
            </Row>
        </Form>
        <div class="table_div">
            <Table :columns="columns" :data="tableData" :loading="Loading">
                <template slot-scope="{ row }" slot="action">
                    <!--                    <Button type="info" size="small" style="margin-right: 5px" @click="handleEdit(index)">编辑</Button>-->
                    <!--                    <Button type="success" size="small" style="margin-right: 5px" @click="remove(row)">删除计划</Button>-->
                    <!--                    <Button type="success" size="small" style="margin-right: 5px" @click="handleView(index)">查看详细</Button>-->
                    <Button type="success" size="small" v-if="row.cbxx0015.length>0" style="margin-right: 5px"
                            @click="hdbg(row.cbxx0015)">查看核对报告
                    </Button>
                </template>
            </Table>
            <Page :total="dataCount" :page-size="pageSize" show-total class="paging"
                  @on-change="handleTableChange" :current="pageNo"></Page>
        </div>
        <pdfModal ref="pdfModal"></pdfModal>
    </div>
</template>

<script>
    import {postAction} from '@/api/request'
    import {CommonMixin} from '@/views/common/js/CommonMixin'
    import dictSelect from '@/components/dictSelect/dictSelect.vue'
    import DateFormat from '@/plugins/format.js'
    import pdfModal from '@/components/system/pdfModal'

    export default {
        mixins: [CommonMixin],
        components: {
            dictSelect,pdfModal
        },
        data() {
            return {
                rules: {
                    ccxx0001: [
                        {
                            required: true, message: '复核月度不能为空', trigger: 'blur',
                            pattern: /.+/
                        }
                    ],
                    ccxx0002: [
                        {
                            required: true, message: '计划执行时间不能为空', trigger: 'blur',
                            pattern: /.+/
                        }
                    ],
                },
                columns: [
                    // {
                    //     title: 'oss',
                    //     key: 'cbxx0015',
                    //     align: 'center',
                    //     width: '100'
                    // },
                    {
                        title: '复核月度',
                        key: 'cbxx0010',
                        align: 'center',
                        width: '100'
                    },
                    {
                        title: '户主姓名',
                        key: 'cbxx0001',
                        align: 'center',
                        width: '100'
                    },
                    {
                        title: '证件号码',
                        key: 'cbxx0002',
                        align: 'center',
                        width: '200'
                    },
                    {
                        title: '复核数据状态',
                        key: 'cbxx0013',
                        align: 'center',
                        width: '130',
                        render: (h, params) => {
                            let value = params.row.cbxx0013
                            if (value === '0') {
                                value = '保障数据匹配成功'
                            } else if (value === '1') {
                                value = '保障数据匹配失败'
                            } else if (value === '-21') {
                                value = '属地区划匹配失败'
                            } else if (value === '-1') {
                                value = '核对报告获取失败'
                            }
                            return h('span', value + ' ')
                        },
                    },
                    {
                        title: '核对报告编号',
                        key: 'cbxx0008',
                        align: 'center',
                        width: '200'
                    },
                    {
                        title: '属地区划',
                        key: 'azdf0007',
                        align: 'center',
                        width: '160'
                    },
                    {
                        title: '当前救助状态',
                        key: 'assistancetype',
                        align: 'center',
                        width: '180',
                    },
                    {
                        title: '家庭编号',
                        key: 'azdf0001',
                        align: 'center',
                        width: '180'
                    },
                    {
                        title: '低保证号',
                        key: 'ssca0014',
                        align: 'center',
                        width: '180'
                    },
                    {
                        title: '家庭人口',
                        key: 'ssca0051',
                        align: 'center',
                        width: '100'
                    },
                    {
                        title: '保障人口',
                        key: 'ssca0052',
                        align: 'center',
                        width: '100'
                    },
                    {
                        title: '家庭住址',
                        key: 'azdf0008',
                        align: 'center',
                        width: '180'
                    },
                    {
                        title: '分类救助上浮金额',
                        key: 'ssca0025',
                        align: 'center',
                        width: '100'
                    },
                    {
                        title: '高龄补贴金额',
                        key: 'ssca0065',
                        align: 'center',
                        width: '180'
                    },
                    {
                        title: '救助金额',
                        key: 'ssca0026',
                        align: 'center',
                        width: '130'
                    },
                    {
                        title: '总金额',
                        key: 'fAllMoney',
                        align: 'center',
                        width: '130'
                    },
                    {
                        title: '批准时间',
                        key: 'ssca0006',
                        align: 'center',
                        width: '120'
                    },
                    {
                        title: '性别',
                        key: 'azcp0004',
                        align: 'center',
                        width: '100',
                        render: (h, params) => {
                            let value = params.row.azcp0004
                            if (value === '1') {
                                value = '男'
                            } else if (value === '2') {
                                value = '女'
                            }
                            return h('span', value + ' ')
                        },
                    },
                    {
                        title: '户籍类别',
                        key: 'azcp0013',
                        align: 'center',
                        width: '140'
                    },
                    {
                        title: '民族',
                        key: 'azcp0007',
                        align: 'center',
                        width: '100'
                    },
                    {
                        title: '文化程度',
                        key: 'azcp0008',
                        align: 'center',
                        width: '120'
                    },
                    {
                        title: '健康状况',
                        key: 'azcp0009',
                        align: 'center',
                        width: '150'
                    },
                    {
                        title: '残疾类别',
                        key: 'azcp0504',
                        align: 'center',
                        width: '150'
                    },
                    {
                        title: '残疾等级',
                        key: 'azcp0505',
                        align: 'center',
                        width: '150'
                    },
                    {
                        title: '劳动能力丧失情况',
                        key: 'azcp0502',
                        align: 'center',
                        width: '150'
                    },
                    {
                        title: '操作',
                        fixed: 'right',
                        key: 'action',
                        align: 'center',
                        slot: 'action',
                        width: '150',
                        className: 'nopadding',
                    }
                ],
                tableData: [],
                Loading: false,
                url: {
                    list: "/api/ac/subsistence/ss08012Service/getFhPageList",
                    edit: "/api/ac/subsistence/ss08012Service/update",
                    add: "/api/ac/subsistence/ss08012Service/insert",
                    monthFhHandle: "/api/ac/subsistence/ss08012Service/updateMonthFhHandle"
                },
                queryParam: {type: 'manual'},
                visible: false,
                show_detail: true,
                showSubmit: true,
                dataCount: 0,
                pageSize: 10,
                modal: false,
                title: ""
            }
        },
        methods: {
            hdbg(item) {
                //查看核对报告
                this.$Modal.confirm({
                    title: '核对报告打印无效，是否确认？？',
                    onOk: () => {
                        this.$refs.pdfModal.showFile(item);
                        this.$refs.pdfModal.modalKey = this.uuid();
                    }
                })
            },
            searchQuery2() {
                if (this.queryParam.cbxx0010) {
                    this.queryParam.cbxx0010 = DateFormat(this.queryParam.cbxx0010, 'YYYY-MM');
                }
                this.loadData();
            },
            handleAdd() {
                let that = this;
                that.title = "行政区划录入"
                let record = {};
                that.visible = true
                that.show_detail = false
                that.showSubmit = true
                that.formData = Object.assign({}, record)
                that.formData.ccxx0012 = 'manual'
            },
            handleEdit(index) {
                let that = this;
                that.title = "执行计划编辑"
                let record = that.tableData[index];
                if (record.id) {
                    that.visible = true
                    that.show_detail = false
                    that.showSubmit = true
                    that.formData = Object.assign({}, record)
                    that.formData.ccxx0002 = new Date(record.ccxx0002)
                } else {
                    that.visible = false
                    that.show_detail = true
                }
            },
            handleView(index) {
                let that = this;
                that.title = "执行计划查看"
                let record = that.tableData[index];
                if (record.id) {
                    that.visible = true
                    that.showSubmit = false
                    that.formData = Object.assign({}, record)
                    that.formData.ccxx0002 = new Date(record.ccxx0002)
                } else {
                    that.visible = false
                }
            },
            handleSubmit(name) {
                let that = this;
                let validate = true;
                let err_msg = [];
                for (let item of that.fieldsToValidate) {

                    that.$refs[name].validateField(item, (error) => {
                        if (error) {
                            validate = false;
                            err_msg.push(error);
                        }
                    })
                }
                if (validate) {
                    let that = this;
                    let dataParam = {
                        id: that.formData.id,
                        ccxx0001: DateFormat(that.formData.ccxx0001, 'YYYY-MM'),
                        ccxx0002: DateFormat(that.formData.ccxx0002, 'YYYY-MM-DD'),
                        ccxx0012: 'manual'
                    }
                    let url = null;
                    if (dataParam.id == null) {
                        url = that.url.add
                    } else {
                        url = that.url.edit
                    }
                    postAction(url, dataParam).then((res) => {
                        if (res.data.errcode == 0) {
                            that.visible = false
                            this.$Message.success("提交成功！")
                            this.loadData();
                        } else {
                            this.$Message.error(res.data.data.msg);
                        }
                    })
                }
            },
        },
        created() {
            this.loadData();
        },
    }
</script>
<style scoped>
    .paging {
        float: right;
        margin-top: 10px;
    }

    /deep/ .ivu-upload-list {
        display: none;
    }
</style>
